﻿<UserControl x:Class="Common.Controls.Controls.FilterControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:Common.Controls.Converters"
             xmlns:controls="clr-namespace:Common.Controls.Controls"
             mc:Ignorable="d" d:DesignHeight="32" d:DesignWidth="277"
             x:Name="filterControl"
             >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Common.Dialogs;component/Styles/CommonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <converters:TextFilterInputVisibilityConverter x:Key="TextFilterInputVisibilityConverter"/>
            <converters:DateFilterInputVisibilityConverter x:Key="DateFilterInputVisibilityConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Border BorderThickness="2" BorderBrush="Gray" Background="LightGray" CornerRadius="8">
        <Grid Margin="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Image Source="../Images/ZoomHS.png" Grid.Column="0" Width="16" Height="16"/>
            
            <TextBox x:Name="FilterValueTextBox" Grid.Column="1" 
                     Text="{Binding ElementName=filterControl,Path=SelectedFilterValue,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                     Style="{StaticResource BorderlessTextBox}"
                     Visibility="{Binding ElementName=filterControl,Path=SelectedFilterField,Mode=TwoWay,Converter={StaticResource TextFilterInputVisibilityConverter}}"
                     KeyDown="FilterValueTextBox_KeyDown"
                     TextChanged="FilterValueTextBox_TextChanged"/>
            <controls:DateIntervalInputBox x:Name="FilterValueDateBox" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Left"
                     Visibility="{Binding ElementName=filterControl,Path=SelectedFilterField,Mode=TwoWay,Converter={StaticResource DateFilterInputVisibilityConverter}}"
                     OnDateIntervalChanged="FilterValueDateBox_OnDateIntervalChanged"/>
            
            <ComboBox x:Name="FilterFieldComboBox" Grid.Column="2" HorizontalContentAlignment="Right"
                      Style="{StaticResource BorderlessComboBox}" Margin="-2,0,0,0"
                      ItemsSource="{Binding ElementName=filterControl,Path=FilterFields}" 
                      SelectedItem="{Binding ElementName=filterControl,Path=SelectedFilterField,Mode=TwoWay}" 
                      ItemContainerStyle="{Binding ElementName=filterControl,Path=ItemContainerStyle}"
                      SelectionChanged="FilterFieldComboBox_SelectionChanged" Width="150">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding FieldDisplayName}" Margin="0,0,4,0"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
                <ComboBox.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Border Margin="4" Background="LightSteelBlue" HorizontalAlignment="Stretch">
                                    <TextBlock FontWeight="Bold" FontSize="12" Text="{Binding Name}" Margin="2"/>
                                </Border>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ComboBox.GroupStyle>
            </ComboBox>
        </Grid>
    </Border>
</UserControl>
